<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Badge_Form_Admin_Manage_Create extends Engine_Form {
	public $_error = array ();
	
	public function init() {
		$user = Engine_Api::_ ()->user ()->getViewer ();
		$user_level = Engine_Api::_ ()->user ()->getViewer ()->level_id;
		
		$this->setTitle ( 'Create New Badge' )->setDescription ( 'Compose your new badge below, then click "Save Badge" to save the badge.' )->setAttrib ( 'name', 'badges_create' );
		
		// prepare categories
		$categories = Engine_Api::_ ()->badge ()->getCategories ();
		if (count ( $categories ) != 0) {
			$categories_prepared = Engine_Api::_ ()->badge ()->convertCategoriesToArray ( $categories );
			$categories_prepared = array ("" => "" ) + $categories_prepared;
			
			// category field
			$this->addElement ( 'Select', 'category_id', array ('label' => 'Category', 'multiOptions' => $categories_prepared, 'allowEmpty' => false, 'required' => true, 'validators' => array (array ('NotEmpty', true ) ), 'filters' => array ('Int' ) ) );
		}
		
		$this->addElement ( 'File', 'photo', array ('label' => 'Badge Photo', 'allowEmpty' => false, 'required' => true ) );
		$this->photo->addValidator ( 'Extension', false, 'jpg,png,gif' );
		
		$this->addElement ( 'Text', 'title', array ('label' => 'Title', 'description' => 'Enter a title for this badge', 'allowEmpty' => false, 'required' => true, 'filters' => array ('StripTags', new Engine_Filter_Censor (), new Engine_Filter_StringLength ( array ('max' => '127' ) ) ) ) );
		
		// Description
		$this->addElement ( 'Textarea', 'description', array ('label' => 'Short Description', 'maxlength' => '255', 'filters' => array ('StripTags', new Engine_Filter_Censor (), new Engine_Filter_StringLength ( array ('max' => '255' ) ) ) ) );
		
		$this->addElement ( 'TinyMce', 'body', array ('label' => 'Full Details', 'description' => 'Please provide (optional) full description of this badge, which would be shown under the "Lear More" tab on badge\'s profile view page.', //'required' => true,
		//'allowEmpty' => false,
		'filters' => array (new Engine_Filter_Censor () )// new Radcodes_Lib_Filter_Html(array('allowedTags'=>$allowed_html,'useDefaultLists'=>false,'allowedAttributes'=>$allowed_htmlattrs))
		, 'editorOptions' => array ('mode' => 'exact', 'elements' => 'body', 'width' => 450, 'height' => 260, 'plugins' => "emotions, table, fullscreen, media, preview, paste, style, layer, xhtmlxtras", 'theme_advanced_buttons1' => "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,link,unlink,anchor,charmap,image,media,|,hr,removeformat,cleanup,code", 'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,blockquote,|,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,preview", 'theme_advanced_buttons3' => "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|,insertlayer,moveforward,movebackward,absolute", 'theme_advanced_buttons4' => "tablecontrols,|,styleprops,attribs,|,cite,del,ins" )

		 ) );
		
		$this->addElement ( 'Checkbox', 'search', array ('label' => 'Show this badge in browse and search results', 'value' => 1 ) );
		
		$this->addElement ( 'Checkbox', 'member_profile_display', array ('label' => 'Show this badge on member profile page (via widgets integration)', 'value' => 1 ) );
		
		$this->addElement ( 'Checkbox', 'requirement_tab_display', array ('label' => 'Display "Requirements" tab on badge\'s profile page', 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'membership_type', array ('label' => 'Assignment Type', 'description' => 'There are 2 different ways of assignment this badge to members. In "Award" mode, administrator will have to manually assign  the badge to selected member or group of members (see "Awards" tab). In "Mapping" mode, the badge will be automatically assigned to any members who meet membership requirements.', 'allowEmpty' => false, 'required' => true, 'multiOptions' => array (Badge_Model_Badge::MEMBERSHIP_TYPE_AWARD => 'Award - Manual assignment for members.', Badge_Model_Badge::MEMBERSHIP_TYPE_MAPPING => 'Mapping - Automatic assignment for members.' ), 'value' => Badge_Model_Badge::MEMBERSHIP_TYPE_AWARD ) );
		
		$userTableName = Engine_Api::_ ()->getItemTable ( 'user' )->info ( 'name' );
		$awardTableName = Engine_Api::_ ()->badge ()->getAwardTable ()->info ( 'name' );
		
		$this->addElement ( 'Select', 'awards_order', array ('label' => 'Awards Display Ordering', 'description' => "How would badge's awarded members be sorted by?", 'multiOptions' => array ("$awardTableName.creation_date DESC" => "Awarded Date Descending", "$awardTableName.creation_date ASC" => "Awarded Date Ascending", "$awardTableName.title ASC" => "Award Title", "$awardTableName.view_count DESC" => "Award Most Viewed", "$awardTableName.comment_count DESC" => "Award Most Commented", "$awardTableName.like_count DESC" => "Award Most Liked", "$awardTableName.rank ASC" => "Award Order Ranking Ascending", "$awardTableName.rank DESC" => "Award Order Ranking Descending", "$userTableName.creation_date DESC" => "Member Joined Date Descending", "$userTableName.creation_date ASC" => "Member Joined Date Ascending", "$userTableName.modified_date DESC" => "Member Last Updated", "$userTableName.view_count DESC" => "Member Most Viewed Profile", "$userTableName.invites_used DESC" => "Member Most Sent Invites", "$userTableName.displayname ASC" => "Member Display Name" ), 'value' => "$awardTableName.creation_date DESC" ) );
		
		$this->addElement ( 'Select', 'members_order', array ('label' => 'Members Display Ordering', 'description' => "How would badge's members be sorted by?", 'multiOptions' => array ("$userTableName.creation_date DESC" => "Joined Date Descending", "$userTableName.creation_date ASC" => "Joined Date Ascending", "$userTableName.modified_date DESC" => "Last Updated", "$userTableName.view_count DESC" => "Most Viewed Profile", "$userTableName.invites_used DESC" => "Most Sent Invites", "$userTableName.displayname ASC" => "Display Name" ), 'value' => "$userTableName.creation_date DESC" ) );
		
		$this->addElement ( 'Heading', 'heading1', array ('label' => 'Membership Requirements' ) );
		
		$this->addElement ( 'Radio', 'user_profile_photo', array ('label' => 'Member Profile Photo', 'allowEmpty' => false, 'required' => true, 'multiOptions' => array ('1' => 'Member must have profile photo.', '0' => 'Any members regardless whether they have profile photo or not.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Text', 'user_view_count', array ('label' => 'Member Profile View Count', 'description' => 'Enter number of profile views the member must have accumulated', 'value' => 0, //'allowEmpty' => false,
		//'required' => true,
		'filters' => array ('Int' ), 'validators' => array ('Int' )//new Zend_Validate_GreaterThan(0),
		 ) );
		
		$this->addElement ( 'Text', 'user_invites_used', array ('label' => 'Member Invites Used', 'description' => 'Enter number of invites the member must have sent', 'value' => 0, //'allowEmpty' => false,
		//'required' => true,
		'filters' => array ('Int' ), 'validators' => array ('Int' )//new Zend_Validate_GreaterThan(0),
		 ) );
		
		$this->addElement ( 'Text', 'user_account_age', array ('label' => 'Member Signup Days', 'description' => 'How many days must have been passed since member signed up?', 'value' => 0, 'filters' => array ('Int' ), 'validators' => array ('Int' ) ) );
		
		$this->addElement ( 'Text', 'user_login_days', array ('label' => 'Member Last Login Days', 'description' => 'How many days must NOT be passed since member last logged in?', 'value' => 0, 'filters' => array ('Int' ), 'validators' => array ('Int' ) ) );
		
		$this->addElement ( 'Radio', 'user_level_settings', array ('label' => 'Member Level Settings', 'allowEmpty' => false, 'required' => true, 'multiOptions' => array ('0' => 'All member levels', '1' => 'Selected member levels' ), 'value' => 0 ) );
		
		$level_options = Engine_Api::_ ()->badge ()->getMemberLevelArray ();
		
		$this->addElement ( 'MultiCheckbox', 'user_level_ids', array ('label' => 'Allowed Member Levels', 'description' => 'Members who belong to selected member levels below are allowed to have this badge.', 'multiOptions' => $level_options ) );
		
		$this->addElement ( 'Radio', 'user_network_settings', array ('label' => 'Member Network Settings', 'allowEmpty' => false, 'required' => true, 'multiOptions' => array ('0' => 'All member networks', '1' => 'Selected member networks' ), 'value' => 0 ) );
		
		$network_options = Engine_Api::_ ()->badge ()->getNetworkArray ();
		
		$this->addElement ( 'MultiCheckbox', 'user_network_ids', array ('label' => 'Allowed Member Networks', 'description' => 'Members who belong to selected networks below are allowed to have this badge.', 'multiOptions' => $network_options ) );
		
		$this->addElement ( 'Radio', 'user_profile_settings', array ('label' => 'Member Profile Settings', 'allowEmpty' => false, 'required' => true, 'multiOptions' => array ('0' => 'All member profiles', '1' => 'Selected member profiles' ), 'value' => 0 ) );
		
		$profile_options = Engine_Api::_ ()->badge ()->getProfileTypeArray ();
		
		$this->addElement ( 'MultiCheckbox', 'user_profile_ids', array ('label' => 'Allowed Member Profiles', 'description' => 'Members who belong to selected profile types below are allowed to have this badge.', 'multiOptions' => $profile_options ) );
		
		$this->addElement ( 'Text', 'include_user_ids', array ('label' => 'Permanent Included Members', 'description' => 'To force certain members to have this badge regardless whether they meet requirements or not, please enter their member IDs (comma seperated) in box below.' ) );
		
		$this->addElement ( 'Text', 'exclude_user_ids', array ('label' => 'Permanent Excluded Members', 'description' => 'To force certain members to have not this badge regardless whether they meet requirements or not, please enter their member IDs (comma seperated) in box below.' ) );
		
		$this->addElement ( 'Radio', 'award_member_request', array ('label' => 'Award Member Request', 'description' => 'Who can submit request to have this badge as an award?', 'multiOptions' => array (2 => 'All registered members', 1 => 'Only members who meet membership requirements', 0 => 'No requests are allowed' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'award_members_simple', array ('label' => 'Awarded Members Display Mode', 'description' => 'Would you like to override the "Awarded Members" tab awards display style with simple "Members" tab as if it is a Mapping (automatic) badge type?', 'multiOptions' => array (1 => 'Yes, use simple mode - only display member names', 0 => 'No, use default setting - display members with awards info' ), 'value' => 0 ) );
		
		$this->addElement ( 'Text', 'rank', array ('label' => 'Member Profile Order', 'description' => 'Badges that appear on member profile integration will be sorted by this number in ascending order.', 'value' => 0, 'filters' => array ('Int' ), 'validators' => array ('Int' ) ) );
		
		// Buttons
		$this->addElement ( 'Button', 'submit', array ('label' => 'Save Badge', 'type' => 'submit', 'ignore' => true, 'decorators' => array ('ViewHelper' ) ) );
		
	/*
    $this->addElement('Cancel', 'cancel', array(
      'label' => 'cancel',
      'link' => true,
      'prependText' => ' or ',
      'decorators' => array(
        'ViewHelper'
      )
    ));
    
    
    $this->addDisplayGroup(array('submit', 'cancel'), 'buttons');
    $button_group = $this->getDisplayGroup('buttons');
    $button_group->addDecorator('DivDivDivWrapper');    
		*/
	}

}